<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<meta name="apple-mobile-web-app-capable" content="yes"><!--删除默认的苹果工具栏和菜单栏-->
		<meta name="apple-mobile-web-app-status-bar-style" content="black" /><!--状态栏显示为黑色-->
		<meta name="format-detection" content="telephone=no" /><!--电话号码不被显示为拨号连接-->
		<title>融资融券交易终端</title>
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/layer/layer.css" id="layui_layer_layercss"/>
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/css/weui.css" />
		<link rel="stylesheet" href="<?php echo STATIC_SERVER; ?>/mobile/css/style.css" />
		<script src="<?php echo STATIC_SERVER; ?>/mobile/js/jquery-1.12.1.min.js"></script>
		<script src="<?php echo STATIC_SERVER; ?>/mobile/layer/layer.js"></script>
	</head>
	<body>
		<div class="my-pic">
			<span>基本资料</span>
		</div>
		<div class="xinsu-section" style="padding-top: 42px;">
			<div class="xinsu-datum">
				<div class="weui-cells xinsu-cells">
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>账号：<span class="xinsu-color-gray"><?php echo $_SESSION['user']['username']; ?></span></p>
						</div>
					</div>
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>姓名：<span class="xinsu-color-gray"><?php echo $_SESSION['user']['nickname']; ?></span></p>
						</div>
					</div>
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>买入手续费：<span class="xinsu-color-gray"><?php echo $common_info['bull_cost'] * 100; ?>%</span></p>
						</div>
					</div>
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>卖出手续费：<span class="xinsu-color-gray"><?php echo $common_info['sell_cost'] * 100; ?>%</span></p>
						</div>
					</div>
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>结算费：<span class="xinsu-color-gray"><?php echo $common_info['save_cost'] * 100; ?>%/天</span></p>
						</div>
					</div>
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>最大持仓天数：<span class="xinsu-color-gray"><?php echo $common_info['save_day']; ?>天</span></p>
						</div>
					</div>
					<div class="weui-cell">
						<div class="weui-cell__bd">
							<p>手机号：<span class="xinsu-color-gray"><?php echo $_SESSION['user']['mobile']; ?></span></p>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="weui-tabbar xinsu-tabbar">
		    <a href="/stock/bull" class="weui-tabbar__item <?php if ($common_info['action'] == 'bull') { ?>xinsu-current<?php } ?>">
			    <div class="weui-tabbar__icon">
			        <i class="xinsu-icon-font xinsu-icon-deal"></i>
			    </div>
		      	<p class="weui-tabbar__label">交易</p>
		    </a>
		    <a href="/stock/index" class="weui-tabbar__item <?php if ($common_info['action'] != 'bull' && $common_info['controller'] == 'stock') { ?>xinsu-current<?php } ?>">
			    <div class="weui-tabbar__icon">
			        <i class="xinsu-icon-font xinsu-icon-search"></i>
			    </div>
			    <p class="weui-tabbar__label">查询</p>
		    </a>
		    <a href="/user/asset" class="weui-tabbar__item <?php if ($common_info['action'] == 'asset' || $common_info['controller'] == 'atm') { ?>xinsu-current<?php } ?>">
		      	<div class="weui-tabbar__icon">
		        	<i class="xinsu-icon-font xinsu-icon-asset"></i>
		      	</div>
		      	<p class="weui-tabbar__label">资产</p>
		    </a>
		    <a href="/" class="weui-tabbar__item <?php if (($common_info['action'] != 'asset' && $common_info['controller'] == 'user') || $common_info['controller'] == 'index') { ?>xinsu-current<?php } ?>">
		      	<div class="weui-tabbar__icon">
		        	<i class="xinsu-icon-font xinsu-icon-user"></i>
		      	</div>
		      	<p class="weui-tabbar__label">我的</p>
		    </a>
		</div>
	</body>
	<script>
		//底部导航隐藏
		var original = document.documentElement.clientHeight;
		window.addEventListener("resize", function() {
			var resizeHeight = document.documentElement.clientHeight;
			if(resizeHeight != original) {
				$('.xinsu-tabbar').hide()
			} else {
				$('.xinsu-tabbar').show()
			}
		});
		var token = "<?php echo $token; ?>";
		//退出登录
		function logout() {
			layer.confirm('您确定要退出？', {icon: 3}, function () {
				stock = system_info = -1
				var url = "/user/logout";
				layer.closeAll();
				http_request_post(url, null, function(res) {
					layer.msg(res.msg, {time: 800}, function () {
						//跳转到登录页面
						location.href = "/user/login";
					});
				});
			});
		}
		
		//提交表单
        var sub = 0;
		$("form").submit(function () {
			//判断提交方式：get-搜索专用，post-保存专用
			var method = $(this).attr("method");
			if (method == "post") {
				//保存专用
				var rmsg = "";
				var data = $(this).serialize();
				if ("<?php echo $common_info['action']; ?>" == "bull") {
					var msg = "您是否确定以上交易？";
					var bull_type = $("input[name='bull_type']:checked").val();
					var price_type = $("input[name='price_type']:checked").val();
					
					//股票类型
					if (bull_type == 1) {
						rmsg += "融资";
					} else {
						rmsg += "融券";
					}
					
					//交易类型
					if (price_type == 0) {
						rmsg += "市价";
					} else {
						rmsg += "限价";
					}
					rmsg += "委托处理成功！";
				} else {
					var msg = "您是否确执行该操作？";
				}
				data += '&token='+token;
				layer.confirm(msg, {icon: 3}, function () {
                    sub += 1;
					layer.closeAll();
                    if (sub == 1) {
                        http_request_post("", data, function (result) {
                            if (rmsg == "") {
                                layer.msg(result.msg, {time:800}, function (){
                                    if (result.data != "") {
                                        location.href = result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            } else {
                                layer.alert(rmsg, {icon:1, closeBtn:0}, function(){
                                    if (result.data != "") {
                                        location.href = result.data;
                                    } else {
                                        location.reload();
                                    }
                                });
                            }
                        });
                    }
				});
				return false;
			} else {
				//搜索专用
				var data = $(this).serializeArray();
				var	url = "/<?php echo $common_info['controller']; ?>/<?php echo $common_info['action']; ?>";
				$.each(data, function(key, val) {
					if (val.value == "") {
						url += "/0";
					} else {
						url += "/" + val.value;
					}
				});
				location.href = url;
				return false;
			}
		})
		
		//通用post请求
		function http_request_post(url, data, callback) {
			if (url != "") {
				url = url;
			}
			$.ajax({
				type : 'post',  
				url : url,
				dataType : 'json',
				data : data,
				success : function(repones) {
					if (repones.status == 1) {
						if (typeof callback === "function") {
							callback(repones);
							return false;
						} else {
							layer.msg('请求加载数据失败，请重新加载');
						}
					} else if (repones.status == 2) {
						stock = system_info = -1
						layer.msg(repones.msg, {time:800}, function() {
							location.href = "/user/login";
						});
						return false;
					} else if (repones.status == 0) {
						token = repones.token;
						layer.msg(repones.msg);
						stock = system_info = -1
						return false;
					} else {
						layer.msg(repones.msg);
						stock = system_info = -1
						return false;
					}
				},
				error : function () {
					layer.load(1, {shade: [0.1,'#fff'], time:500}, function(){
						location.reload();
					});
					return false;
				}
			});
			return false;
		}
	</script>
</html>